<?php 
				if(isset($_GET['destination_from']))
					$destination_from = $_GET['destination_from'];
				if(isset($_GET['destination_to']))
					$destination_to = $_GET['destination_to'];
				if(isset($_GET['length_of_stay']))
					$length_of_stay = $_GET['length_of_stay'];	
					
				if(isset($_GET['st']))
					$st = $_GET['st'];
					
				$aterm = array();
				$arayid = 0;	
				if($st=="vietnam")	
				{
				 	$term = "vietnam-tourism";
				 	$arayid = 0;
				}
				else 
				{
					$myterm = get_term_by('slug', 'vietnam-tourism', 'tourism');
					//print_r($myterm);					
					$args = array('title_li'  => '','orderby' => 'name','order' =>'ASC','taxonomy' => 'tourism','exclude' => array($myterm->term_id),'hide_empty' => 0,'hierarchical'  => true,'depth'  => 1);
 					$category = get_categories($args);
 					foreach ($category as $value) 
 					{
 						$aterm[] = $value->slug;
 					}					
					$arayid = 1;
				}				
				global $paged;
				
				if($destination_from != "" && $destination_to == "" && $length_of_stay == "")
				{
					## 1 metakey
					$posts_per_page		= 21; 
					$post_type			= 'tour'; 
					$orderby			= 'date'; 
					$order				= 'DESC'; 
					$meta_key			= $wpdb->prefix.'destination_from'; 
					$meta_value			= $destination_from; 	
					$args  = db_query_posts_in_terms_child_multi_1metakey_page($posts_per_page, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key, $meta_value, $paged);
					$args2 = db_query_posts_in_terms_child_multi_1metakey_page(-1, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key, $meta_value, $paged);
					$result = query_posts($args2);
					$counts = count($result);
				}
				
				if($destination_from == "" && $destination_to != "" && $length_of_stay == "")
				{
					## 1 metakey
					$posts_per_page		= 21; 
					$post_type			= 'tour'; 
					$orderby			= 'date'; 
					$order				= 'DESC'; 
					$meta_key			= $wpdb->prefix.'destination_to'; 
					$meta_value			= $destination_to; 	
					$args = db_query_posts_in_terms_child_multi_1metakey_page($posts_per_page, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key, $meta_value, $paged);
					$args2 = db_query_posts_in_terms_child_multi_1metakey_page(-1, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key, $meta_value, $paged);
					$result = query_posts($args2);
					$counts = count($result);
				}
				
				if($destination_from == "" && $destination_to == "" && $length_of_stay != "")
				{
					## 1 metakey
					## 1 metakey
					$posts_per_page		= 21; 
					$post_type			= 'tour'; 
					$orderby			= 'date'; 
					$order				= 'DESC'; 
					$meta_key			= $wpdb->prefix.'lenght_of_stay'; 
					$meta_value			= $length_of_stay; 	
					$args = db_query_posts_in_terms_child_multi_1metakey_page($posts_per_page, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key, $meta_value, $paged);
					$args2 = db_query_posts_in_terms_child_multi_1metakey_page(-1, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key, $meta_value, $paged);
					$result = query_posts($args2);
					$counts = count($result);
				}
				
				if($destination_from != "" && $destination_to != "" && $length_of_stay == "")
				{
					## 2 metakey
					$posts_per_page			= 21;
					$post_type				= 'tour';
					$order_by				= 'date';
					$order					= 'DESC';
					$meta_key1				= $wpdb->prefix.'destination_from';
					$meta_value1			= $destination_from;
					$meta_key2				= $wpdb->prefix.'destination_to';
					$meta_value2			= $destination_to;
					
					$args = db_query_posts_in_terms_child_multi_2metakey_page($posts_per_page, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key1, $meta_value1, $meta_key2, $meta_value2, $paged);
					$args2 = db_query_posts_in_terms_child_multi_2metakey_page(-1, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key1, $meta_value1, $meta_key2, $meta_value2, $paged);
					$result = query_posts($args2);
					$counts = count($result);
				}
				
				if($destination_from != "" && $destination_to == "" && $length_of_stay != "")
				{
					## 2 metakey
					$posts_per_page			= 21;
					$post_type				= 'tour';
					$order_by				= 'date';
					$order					= 'DESC';
					$meta_key1				= $wpdb->prefix.'destination_from';
					$meta_value1			= $destination_from;
					$meta_key2				= $wpdb->prefix.'lenght_of_stay';
					$meta_value2			= $length_of_stay;
					
					$args = db_query_posts_in_terms_child_multi_2metakey_page($posts_per_page, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key1, $meta_value1, $meta_key2, $meta_value2, $paged);
					$args2 = db_query_posts_in_terms_child_multi_2metakey_page(-1, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key1, $meta_value1, $meta_key2, $meta_value2, $paged);
					$result = query_posts($args2);
					$counts = count($result);
				}
				if($destination_from == "" && $destination_to == "" && $length_of_stay == "")
				{
					$posts_per_page			= 21;
					$post_type				= 'tour';
					$args = db_query_posts_in_terms_child_multi_1taxonomy_page($posts_per_page, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $paged);
					$args2 = db_query_posts_in_terms_child_multi_1taxonomy_page(-1, $post_type, 'tourism', 'slug', $term,$aterm,$arayid,$paged);
					$result = query_posts($args2);
					$counts = count($result);
					//print_r($args);
				}
				if($destination_from == "" && $destination_to != "" && $length_of_stay != "")
				{
					## 2 metakey
					$posts_per_page			= 21;
					$post_type				= 'tour';
					$order_by				= 'date';
					$order					= 'DESC';
					$meta_key1				= $wpdb->prefix.'destination_to';
					$meta_value1			= $destination_to;
					$meta_key2				= $wpdb->prefix.'lenght_of_stay';
					$meta_value2			= $length_of_stay;
					
					$args = db_query_posts_in_terms_child_multi_2metakey_page($posts_per_page, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key1, $meta_value1, $meta_key2, $meta_value2, $paged);
					$args2 = db_query_posts_in_terms_child_multi_2metakey_page(-1, $post_type, 'tourism', 'slug', $term,$aterm,$arayid, $meta_key1, $meta_value1, $meta_key2, $meta_value2, $paged);
					$result = query_posts($args2);
					$counts = count($result);
				}
				if($destination_from != "" && $destination_to != "" && $length_of_stay != "")
				{
					## 3 metakey
					$argscount 	= db_query_posts_in_terms_child_multi_3metakey_page(-1, 'tour', 'tourism', 'slug', $term,$aterm,$arayid, $wpdb->prefix.'destination_from', $destination_from, $wpdb->prefix.'destination_to', $destination_to, $wpdb->prefix.'lenght_of_stay', $length_of_stay, $paged);
            		//print_r($argscount);
	            	$result = query_posts($argscount);
	            	$counts = count($result);
	            	##
	                $args		= db_query_posts_in_terms_child_multi_3metakey_page(21, 'tour', 'tourism', 'slug', $term,$aterm,$arayid, $wpdb->prefix.'destination_from', $destination_from, $wpdb->prefix.'destination_to', $destination_to, $wpdb->prefix.'lenght_of_stay', $length_of_stay, $paged);
	                
				}
				
                //print_r($args);                               
                query_posts($args);
?>			
			<div id="content" class="page-searchresults">
            	<?php 
            		include TEMPLATEPATH.'/views/tour/view-search-tour.php';            		
            	?>
            	<div class="content-box-1">
                    <h1 class="label-content-box-1-top">Search Results : <?php echo $counts;?></h1>                    
                    <!-- <span class="found"> results found</span> -->                    
                    <?php                    
                    $html = null;
                    $html.='<ul>';
					require_once TEMPLATEPATH.'/views/tour/loop-tour.php';
                    $html.='</ul>';
                    echo $html;
                    ?>                   
                    <div class="paging">
		            <!-- thêm hoặc bỏ  hide vào prev hoặc next khi ở đầu hoặc cuối-->
		            <?php
		            bt_paginate(); 
		            ?>		            
				</div>
                </div>
            	</div>